package com.synnex.mobile.servier.web.contact.controller.mobile;

import com.synnex.mobile.generic.core.exception.SystemException;
import com.synnex.mobile.generic.core.json.JSONModel;
import com.synnex.mobile.generic.log.dao.annotation.LogClass;
import com.synnex.mobile.generic.log.dao.annotation.LogMethod;
import com.synnex.mobile.generic.web.anotation.mapping.RequestMapping;
import com.synnex.mobile.generic.web.view.ModelAndView;
import com.synnex.mobile.servier.core.contact.bo.ContactBo;
import com.synnex.mobile.servier.web.contact.controller.AbstractContactController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kerryf
 */
@RequestMapping(url = "/mobile")
@LogClass(name = "mobile contact")
public class MobileContactController extends AbstractContactController {

    private static  String[] EXCLUDE_PROPERTIES = new String[]{"updateDate","entryDate","id","seq"};

    @RequestMapping(url = "/contact/listcontact.do")
    @LogMethod(name = "get activity record list ")
    public ModelAndView listcontact(HttpServletRequest request, HttpServletResponse response) {
        try {

            JSONModel jsonModel = JSONModel.create().setExcludes(EXCLUDE_PROPERTIES);

            String link = "http://"+this.getConfig().getFtpHost()+this.getConfig().getFtpDownLoadPath()+"/";
            Map<String, Object> model = new HashMap<String, Object>();
            String key = request.getParameter("title");
            List<ContactBo> boList = contactService.ListContact("");
            model.put("results", boList);
            model.put("link",link);
            jsonModel.setData(model);

            return createJSONModelAndView(jsonModel);

        } catch (Exception e) {
            return createErrorJSONModelAndView(e);
        }
    }

}
